//
//  BlogStatus.swift
//  sinaBlog
//
//  Created by tianxiangyang on 15/12/18.
//  Copyright (c) 2015年 itcast. All rights reserved.
//

import UIKit

class BlogStatus: NSObject {
    //发微博时间
    var created_at:String?
    
    var id:Int64 = 0
    //正文
    var text:String?
    //发微博设备
    var source:String?
    //用户
    var user:User?
    //配图urlstring数组
    var pic_urls:[[String:String]]?{
        didSet{
        
            if  let pics = pic_urls {
            
                pictureURLs = [NSURL]()
                
                for dict in pics {
                
                    var urlString = dict["thumbnail_pic"]
                    
                    //切换成中图
                    urlString = urlString?.stringByReplacingOccurrencesOfString("thumbnail", withString: "bmiddle", options:nil, range: nil)

                    
                    let url = NSURL(string: urlString!)
                    
                    pictureURLs?.append(url!)
                }

            }

        }
    
    }
   //配图URL数组
    var pictureURLs:[NSURL]?
    
    
    //转发微博
    
    var retweeted_status:BlogStatus?
    
    
    
    
    
    
    
    
    init(dict:[String:AnyObject]){
    
     super.init()
        
    setValuesForKeysWithDictionary(dict)
    
    
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
     
    }
    
    
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key == "user" {
            
            if value == nil {return}
            
            let dict = value as? [String:AnyObject]
            
            user = User(dict: dict!)
            
            return
        }
        
        if key == "retweeted_status"{
        
            if value == nil {return}
            
            let dict = value as? [String:AnyObject]
            
            retweeted_status = BlogStatus(dict: dict!)
        
            return
        
        }
        
        
        super.setValue(value, forKey: key)
    }
    
    
    
    var desription:String {
    
        let keys = ["created_at","id","text","source","user"]
        
        return dictionaryWithValuesForKeys(keys).description
    
    }
    
   
}
